import {
  FileInterceptor,
  MemoryStorageFile,
  UploadedFile,
} from '@blazity/nest-file-fastify';
import { IndexInterceptor } from '@libs/common/interceptors';
import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';

import { AttendanceStatisticsService } from './attendance-statistics.service';
import {
  AttendanceStatisticIndexDto,
  FindAttendanceStatisticDto,
  ImportAttendanceStatisticDto,
  StatisticAttendanceStatisticDto,
  StatisticAttendanceWorkHoursDto,
  SyncAttendanceStatisticDto,
} from './dto/attendance-statistic.dto';

@Controller('hr/attendance-statistics')
export class AttendanceStatisticsController {
  constructor(
    private readonly attendanceStatisticsService: AttendanceStatisticsService,
  ) {}

  @Post('index')
  @UseInterceptors(new IndexInterceptor())
  index(@Body() dto: AttendanceStatisticIndexDto) {
    return this.attendanceStatisticsService.index(dto);
  }

  @Post('user/overview')
  overview(@Body() dto: StatisticAttendanceStatisticDto) {
    return this.attendanceStatisticsService.userOverview(dto);
  }

  @Post('user/workHours')
  userWorkHours(@Body() dto: StatisticAttendanceWorkHoursDto) {
    return this.attendanceStatisticsService.userWorkHours(dto);
  }
  // @Post('getcolumnval')
  // getColumnVal(@Body() dto: ColumnAttendanceStatisticDto) {
  //   return this.attendanceStatisticsService.getColumnVal({
  //     dingId: dto.dingId,
  //     fromDate: dto.fromDate,
  //     toDate: dto.toDate,
  //   });
  // }

  // @Post('getAttendanceLog')
  // getAttendanceLog(@Body() dto: SyncAttendanceStatisticDto) {
  //   return this.attendanceStatisticsService.syncAttendanceLog(dto);
  // }

  @Post('import')
  @UseInterceptors(
    FileInterceptor('file', {
      limits: {
        fileSize: Math.pow(1024, 3),
      },
      filter: (req, file) => {
        return true;
      },
    }),
  )
  async import(
    @Body() dto: ImportAttendanceStatisticDto,
    @UploadedFile() file: MemoryStorageFile,
  ) {
    // 单个文件上传
    return this.attendanceStatisticsService.import(dto, file);
  }

  // @Post('/updateData')
  // updateData() {
  //   return this.attendanceStatisticsService.updateData();
  // }

  // @Post('dayPoints')
  // dayPoints(@Body() dto: SyncAttendanceStatisticDto) {
  //   return this.attendanceStatisticsService.dayPoints(dto);
  // }

  // @Post('timeGet')
  // timeGet() {
  //   return this.attendanceStatisticsService.timeGet();
  // }

  @Post('find')
  find(@Body() dto: FindAttendanceStatisticDto) {
    return this.attendanceStatisticsService.find(dto);
  }
}
